//
//  NetWorkManger.swift
//  DouYuZB
//
//  Created by James on 2017/10/15.
//  Copyright © 2017年 James. All rights reserved.
//

import UIKit
import Alamofire

enum MethodType {
    case GET
    case POST
}

class NetWorkManger {
    class func  requestData(type:MethodType = .GET,urlString:String,parameters:[String:String]? = nil,finishCallBack:@escaping (_ result : AnyObject)->()) {
        //1.获取请求类型
        let method = type == .GET ? HTTPMethod.get :  HTTPMethod.post
        
        Alamofire.request(urlString, method: method, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
            
            print(response.request?.url?.absoluteString)
            
            guard let resultData = response.result.value else {
                print("error \(response.result.error)")
                return
            }
            
            //回调结果
            finishCallBack(resultData as AnyObject)
        }
    }
}
